package com.example.test;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.test.DatabaseOpenHelper;
import com.example.test.LoginActivity;

import com.example.test.databinding.ActivityUpdatePasswordBinding;

public class UpdatePasswordActivity extends AppCompatActivity {
    ActivityUpdatePasswordBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityUpdatePasswordBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.updatePassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DatabaseOpenHelper dbHelper = new DatabaseOpenHelper(UpdatePasswordActivity.this);
                String oldPassword = binding.oldPassword.getText().toString();
                String newPassword = binding.newPassword.getText().toString();
                if (dbHelper.changePassword(LoginActivity.usernameA ,oldPassword, newPassword)) {
                    Toast.makeText(UpdatePasswordActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                    finish();
                } else {
                    Toast.makeText(UpdatePasswordActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
